﻿/**
* 命名空间: ICS_Equipment.platform
*
* 功 能： N/A
* 类 名： platform1
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
* V0.01 2021/9/17 13:53:01 小柚子爱学习 初版
*
* Copyright (c) 2021 Lir Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为个人机密信息，未经本人书面同意禁止向第三方披露．　│
*│　版权所有：Vip_Future 　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ICS_Equipment.platform
{
    /// <summary>
    /// platform1.xaml 的交互逻辑
    /// </summary>
    public partial class platform: UserControl
    {
        public platform()
        {
            InitializeComponent();
        }
        //鼠标滚动事件
        private void Canvas_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            double newWidth = mainView.ActualWidth + e.Delta;
            double newHeight = mainView.ActualHeight + e.Delta;
            if (mainView.ActualHeight < 100)
            {
                newHeight = 100;
            }
            if (mainView.ActualWidth < 200)
            {
                newWidth = 200;
            }

            this.mainView.Width = newWidth;
            this.mainView.Height = newHeight;
            this.mainView.SetValue(Canvas.LeftProperty, (this.RenderSize.Width - this.mainView.Width) / 2);
        }
        bool isMoving = false;
        Point _downPoint = new Point(0, 0);
        double left = 0, top = 0;
        //拖放事件
        private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            isMoving = true;
            _downPoint = e.GetPosition(sender as Canvas);
            left = double.Parse(this.mainView.GetValue(Canvas.LeftProperty).ToString());
            top = double.Parse(this.mainView.GetValue(Canvas.TopProperty).ToString());
            (sender as Canvas).CaptureMouse();

        }

        private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            isMoving = false;
            (sender as Canvas).ReleaseMouseCapture();

        }

        private void Canvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMoving)
            {
                Point currentPoint = e.GetPosition(sender as Canvas);
                this.mainView.SetValue(Canvas.LeftProperty, left + currentPoint.X - _downPoint.X);
                this.mainView.SetValue(Canvas.TopProperty, top + currentPoint.Y - _downPoint.Y);

            }

        }
    }
}

